package com.colbby.datahouse.utils;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class ReflectUtils {

	
	public static List<PropertyDescriptor> pros(Class<?> clazz) {
		List<PropertyDescriptor> ps = new ArrayList<>();
		try {
			for(PropertyDescriptor p : Introspector.getBeanInfo(clazz).getPropertyDescriptors()) {
				if(p.getName().equals("class")) continue;
				ps.add(p);
			}
			return ps;
		} catch (IntrospectionException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static Object invoke(Method method, Object owner, Object... args) {
		try {
			return method.invoke(owner, args);
		} catch (IllegalAccessException | IllegalArgumentException
				| InvocationTargetException e) {
			throw new RuntimeException(e);
		}
	}
}
